package com.biqee.action.login;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.biqee.action.base.BaseAction;
import com.biqee.util.StringUtil;
import com.opensymphony.webwork.ServletActionContext;
import com.opensymphony.xwork.ActionContext;

public class LoginAction extends BaseAction {

	private static Logger LOG = Logger.getLogger(LoginAction.class);

	private static final long serialVersionUID = -347701339232120251L;

	public String name;

	public String password;

	public String redirectUrl;

	public HttpServletRequest httpServletRequest;

	public String execute() {
		return "index";
	}

	public String up() {
		if ("mabinda".equals(name) && "tanguotao".equals(password)) {
			ActionContext ctx = ActionContext.getContext();
			HttpServletRequest request = (HttpServletRequest) ctx
					.get(ServletActionContext.HTTP_REQUEST);
			request.getSession().setAttribute("admin", Boolean.TRUE);
			if (StringUtil.isNotBlank(redirectUrl)) {
				HttpServletResponse response = (HttpServletResponse) ctx
						.get(ServletActionContext.HTTP_RESPONSE);
				try {
					response.sendRedirect(redirectUrl);
					return NONE;
				} catch (IOException e) {
					LOG.error(e.getMessage(), e);
				}
			}
			return SUCCESS;

		} else {
			return ERROR;
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public HttpServletRequest getHttpServletRequest() {
		return httpServletRequest;
	}

	public void setHttpServletRequest(HttpServletRequest httpServletRequest) {
		this.httpServletRequest = httpServletRequest;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public String getRedirectUrl() {
		return redirectUrl;
	}

	public void setRedirectUrl(String redirectUrl) {
		this.redirectUrl = redirectUrl;
	}

	

}
